package version.test.controller;


import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import version.test.dto.entity.WeaponEntity;
import version.test.service.impl.WeaponServiceImpl;
import version.test.service.impl.es.WeaponESService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: hzw
 * @time: 2023/1/11 15:14
 */
@RestController
@RequestMapping("/weapon")
public class WeaponController {


    @Resource
    private WeaponServiceImpl weaponService;
    @Autowired
    private WeaponESService weaponESService;


    @PostMapping(value = "/save")
    public void save(@RequestBody String req) {
        WeaponEntity weapon = JSONObject.parseObject(req, WeaponEntity.class);
        weaponService.save(weapon);
    }

    @PostMapping(value = "/get")
    public WeaponEntity get(@RequestParam(name = "id") Long id) {
        return weaponESService.get(id);
    }

    @PostMapping(value = "/findAll")
    public List<WeaponEntity> findAll() {
        return weaponESService.findAll();
    }

    @PostMapping(value = "/page")
    public Page<WeaponEntity> page(@RequestBody String req) {
        WeaponEntity weapon = JSONObject.parseObject(req, WeaponEntity.class);
        return weaponESService.page(weapon);
    }

    @PostMapping(value = "/findByName")
    public List<WeaponEntity> findByName(@RequestParam String name) {
        return weaponESService.findByName(name);
    }

    @PostMapping(value = "/selectByName")
    public com.baomidou.mybatisplus.extension.plugins.pagination.Page<WeaponEntity> selectByName(@RequestParam String name) {
        return weaponService.selectByName(name);
    }

    @PostMapping(value = "/findByCodeOrName")
    public List<WeaponEntity> findByCodeOrName(@RequestParam String param) {
        return weaponESService.findByCodeOrName(param);
    }

    @PostMapping(value = "/pageByName")
    public Page<WeaponEntity> pageByName(@RequestParam String name) {

        return weaponESService.pageByName(name);
    }
}
